package org.example.business;

import org.example.manage.MilkTeaManage;
import org.example.manage.UserManage;
import org.example.model.MilkTea;
import org.example.model.User;

import java.util.ArrayList;
import java.util.List;

public class SearchBusiness {
    public static List<String> setSearch(String search, int type) {
        List<String> list;
        if (type == 1) {
            list = getUserList();
        }
        else {
            list = getTeaList();
        }
        List<String> searchList = new ArrayList<>();
        for (String str : list) {
            if (str.contains(search) && !search.isEmpty()) {
                searchList.add(str);
            }
        }
        return searchList;
    }
    private static List<String> getUserList() {
        List<String> list = new ArrayList<>();
        UserManage manage = new UserManage();
        List<User> userList = manage.selectAll();
        manage.close();
        for (User item : userList) {
            list.add(item.mailbox);
        }
        return list;
    }
    private static List<String> getTeaList() {
        List<String> list = new ArrayList<>();
        List<MilkTea> teaList = new MilkTeaManage().read();
        for (MilkTea item : teaList) {
            list.add(item.milkName);
        }
        return list;
    }
}
